#ifndef STDAFX_H_10C3F2AB_C971_462D_AE43_8D659E613A34
#define STDAFX_H_10C3F2AB_C971_462D_AE43_8D659E613A34
/**
 * \file stdafx.h
 *
 * \brief Pre-compiled header for the SampleCAI project
 *
 * $Id: stdafx.h,v 1.2 2008/04/26 16:04:24 mgh Exp $
 *
 *
 * Copyright (C) 2006, 2008 Michael G. Herstine <sp1ff@pobox.com>
 *
 * Permission to use, copy, or modify this source code is hereby granted
 * free of  charge, provided  that this copyright  notice appear  on all
 * copies  and  on   all  source  code  derived  from   this  code.   No
 * representation is made regarding the suitability of this software for
 * any  purpose.  It  is provided  "as  is" without  express or  implied
 * warranty.
 *
 *
 * This include file  si for standard system include  files, or project-
 * specific  include files  that are  used frequently,  but  are changed
 * infrequently.
 *
 *
 */

/**
 * \mainpage samplecai Sample "Common" Add-In
 *
 * \section samplecai_intro Introduction
 *
 * This is sample code accompanying the article "Common Add-Ins"
 * illustrating how to build a single COM componenet that can be loaded
 * into any of DevStudio 6, Visual Studio 2003+, or Office 2003.
 *
 *
 */

#if defined ( _MSC_VER ) && _MSC_VER >= 1400
#   define _CRT_SECURE_NO_WARNINGS 1     // Get the compiler to *shut*
#   define _CRT_SECURE_NO_DEPRECATE 1    // *up* about deprecated CRT
#endif                                   // functions...

#ifndef STRICT
# define STRICT                          // Turn on strict(er) type-
#endif // ! STRICT                       // checking in Windows headers

#ifndef _ATL_APARTMENT_THREADED
# define _ATL_APARTMENT_THREADED         // Select level of thread-
#endif // not Apartment Threaded         // safety for this server

#ifdef _DEBUG
# define _ATL_DEBUG_QI                   // Turn on ATL QI tracing
#endif // _DEBUG

#ifndef _ATL_NO_AUTOMATIC_NAMESPACE
# define _ATL_NO_AUTOMATIC_NAMESPACE     // Don't use the entire ATL
#endif // ! _ATL_NO_AUTOMATIC_NAMESPACE  // namespace

#ifndef _ATL_STATIC_REGISTRY
# define _ATL_STATIC_REGISTRY            // Static link to the ATL lib
#endif // ! _ATL_STATIC_REGISTRY

#ifndef ATLBASE_H_INCLUDED
# include <atlbase.h>                    // Core ATL classes (that don't
# define ATLBASE_H_INCLUDED              // depend on _Module)
#endif // not <atlbase.h>

#ifndef ATLCOM_H_INCLUDED
# include <atlcom.h>                     // ATL support for building COM
# define ATLCOM_H_INCLUDED               // servers
#endif // not <atlcom.h>

#ifndef ATLCTL_H_INCLUDED
# include <atlctl.h>                     // ATL control support
# define ATLCTL_H_INCLUDED
#endif // not <atlctl.h>

using namespace ATL;                     // Normally I'd never put a
                                         // using declaration in a
                                         // header; this seems to be
                                         // commonly used, however.

#ifndef STRING_INCLUDED
# include <string>                       // For class std::string
# define STRING_INCLUDED
#endif // not <string>

#ifndef ADDAUTO_H_INCLUDED
# include <ADDAUTO.H>                    // DevStudio 6.0 AddIn
//# include <appauto.h>
// There may be some compile error about "bool" in dbgauto.h. 
// To resolve it just rename those 'bool' to be any other name.
//# include <dbgauto.h>
# define ADDAUTO_H_INCLUDED              // interfaces
#endif // not ADDAUTO_H_INCLUDED

#ifndef ADDGUID_H_INCLUDED
# include <ADDGUID.H>                    // DevStudio 6.0 Addin UUIDs
# define ADDGUID_H_INCLUDED
#endif // not ADDGUID_H_INCLUDED

#ifndef APPGUID_H_INCLUDED
# include <APPGUID.H>                    // DevStudio 6.0 Object model
//# include <DBGGUID.H>
# define APPGUID_H_INCLUDED              // UUIDs
#endif // not APPGUID_H_INCLUDED

#pragma warning (push, 3)                // It's just easier to dial the
                                         // compiler warning level down
                                         // for these #imports (since I
                                         // can't do anything about
                                         // them, anyway).
// For interface IDTExtensibility2
// C:\Program Files\Common Files\DESIGNER\MSADDNDR.DLL
#import "libid:AC0714F2-3D04-11D1-AE7D-00A0C90F26F4" version("1.0")    \
  lcid("0")  raw_interfaces_only named_guids

// For Visual Studio Command Bar interfaces
// C:\Program Files\Common Files\Microsoft Shared\MSEnv\vsmso.olb
#import "libid:1CBA492E-7263-47BB-87FE-639000619B15" version("8.0")    \
  lcid("0") raw_interfaces_only named_guids

// For the DTE interface
// C:\Program Files\Common Files\Microsoft Shared\MSEnv\dte80a.olb
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0")    \
  lcid("0") raw_interfaces_only named_guids                            \
  rename("FindText",    "dte80aFindText")                              \
  rename("GetObject",   "dte80aGetObject")                             \
  rename("ReplaceText", "dte80aReplaceText")                           \
  rename("SearchPath",  "dte80aSearchPath")

// For the DTE80 interface
// C:\Program Files\Common Files\Microsoft Shared\MSEnv\dte80.olb
#import "libid:1A31287A-4D7D-413e-8E32-3B374931BD89" version("8.0")    \
  lcid("0") raw_interfaces_only named_guids

// For the MSO object model
// C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL
#import "libid:2DF8D04C-5BFA-101B-BDE5-00AA0044DE52" version("2.3")    \
  lcid("0") raw_interfaces_only /*named_guids*/                        \
  rename("RGB",                "msoRGB")                               \
  rename("DocumentProperties", "msoDocumentProperties")

// For the Excel object model
// C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
#import "libid:00020813-0000-0000-C000-000000000046" version("1.5")    \
  lcid("0") raw_interfaces_only named_guids                            \
  exclude("IFont", "IPicture")                                         \
  rename("RGB",       "xlRGB")                                         \
  rename("CopyFile",  "xlCopyFile")                                    \
  rename("DialogBox", "xlDialogBox")

#pragma warning (pop)

namespace AddInDO = AddInDesignerObjects;               // These names are
namespace MSVSCBs = Microsoft_VisualStudio_CommandBars; // waaaaaaay too
                                                        // long... create
                                                        // aliases.

const UINT SAMPLE_CAI_DEBUG_LOG_LEVEL = 4U;             // This determines
                                                        // the ATLTRACE
                                                        // verbosity for
                                                        // debug builds.

/**
 * \defgroup cmdbar_defns CommandBar Definitions
 *
 * \brief Control management of control bars in the host app
 *
 *
 * There are a few ways for an  AddIn to setup command bars in it's host
 * application.   #define's in this  group will  control how  the Sample
 * AddIn handles this.
 *
 *
 */

/**
 * \brief Use temporary command bars
 *
 * \ingroup cmdbar_defns
 *
 *
 * Set SAMPLECAI_COMMAND_BAR_STYLE to SAMPLECAI_COMMAND_BAR_TEMPORARY to
 * use "temporary" command bars.   These are created when the connection
 * mode    is     ext_cm_Startup    or    ext_cm_AfterStartup    through
 * CommandBars::Add.  They will be  removed by calling the Delete method
 * on the command bar itself when the AddIn is unloaded.
 *
 * This can  be irritating because  the command bar is  re-created every
 * time the AddIn is loaded, even  when the user has chosen to delete it
 * or hide it.   However, I've found this approach to  be less likely to
 * leave the command bar laying around after the AddIn has been unloaded
 * and/or un-installed.
 *
 *
 */

#define SAMPLECAI_COMMAND_BAR_TEMPORARY     ( 1 )

/**
 * \brief Use permanent command bars
 *
 * \ingroup cmdbar_defns
 *
 *
 * Set SAMPLECAI_COMMAND_BAR_STYLE to SAMPLECAI_COMMAND_BAR_PERMANENT to
 * use  "permanent"  command  bars.   These  will be  created  with  the
 * connection mode  is ext_cm_UISetup (through Commands::AddCommandBar),
 * and are never programmatically deleted.
 *
 * These are nice  because they'll respect the user's  choices to delete
 * or hide  the command bar.   It also seems  to be in keeping  with the
 * object model's intent, as I read  it in the MSDN docs.  For instance,
 * the choice to keep the command bar around even if the user unloads it
 * via the  AddIn Manager seems intentional.  However,  the AddIn author
 * is  now  responsible for  deleting  the  thing  separately during  an
 * un-install.   I've also  seen situations  where a  partial un-install
 * left the  command bar present  & un-deletable short of  resetting the
 * IDE.
 *
 *
 */

#define SAMPLECAI_COMMAND_BAR_PERMANENT     ( 2 )

/**
 * \brief Use permanent command bars
 *
 * \ingroup cmdbar_defns
 *
 *
 * Set SAMPLECAI_COMMAND_BAR_STYLE to
 * SAMPLECAI_COMMAND_BAR_SEMIPERMANENT to  use "permanent" command bars,
 * but have  the AddIn  remove them when  the user manually  unloads the
 * AddIn  throught the  AddIn manager.   Think of  this as  a compromise
 * between the other two styles.
 *
 *
 */

#define SAMPLECAI_COMMAND_BAR_SEMIPERMANENT ( 3 )

/**
 * \brief By default, use permanent toolbars
 *
 * \ingroup cmdbar_defns
 *
 *
 */

#define SAMPLECAI_COMMAND_BAR_STYLE SAMPLECAI_COMMAND_BAR_PERMANENT

#define HANDLE_COM_ERROR(clsid, iid, hr)                             \
  catch (const _com_error &ex)                                       \
  {                                                                  \
    LPCTSTR lpszMsg = NULL;                                          \
    _bstr_t bstrDsc = ex.Description();                              \
    if (0 != bstrDsc.length()) lpszMsg = bstrDsc;                    \
    else                       lpszMsg = ex.ErrorMessage();          \
    hr = AtlReportError((clsid), lpszMsg, (iid), ex.Error());        \
  }

#define HANDLE_EXCEPTION(clsid, iid, hr)                             \
  catch (const std::exception &ex)                                   \
  {                                                                  \
    hr = AtlReportError((clsid), ex.what(), (iid), E_FAIL);          \
  }

// Local Variables:
// fill-column: 72
// comment-column: 41
// indent-tabs-mode: nil
// show-trailing-whitespace: t
// End:

#endif // STDAFX_H_10C3F2AB_C971_462D_AE43_8D659E613A34
